Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dashboard index pattern race condition #72899

Merged

Conversation

Dosant
Copy link
Contributor

@Dosant Dosant commented Jul 22, 2020

Summary

Fixes #72601 - "Sometimes filters on non-default-indexpattern dashboard are stuck in warning state".

Please note: it doesn't fix flash of warning state during dashboard loading: #72899 (review). It makes sure we won't stuck in this state. Separate issue to address flickering: #73286

Looks like we hard race condition there for a long time, but noticed it because of #66979 which made it easily noticeable

Problem

There was a race condition when setting index pattern in a dashboard:

Old code:


function updateIndexPattern() {
 const indexPatternsFromPanels = getIndexPatternsFromPanels();

 if (indexPatternsFromPanels.length > 0) {
    setIndexPatterns(indexPatternsFromPanels.length)
 } else {
  fetchDefaultIndexPatterns()
   .then(setIndexPatterns)
 }
} 

And this function was called a bunch of times in the beginning.
On each getOutput$() change:

updateIndexPattern();
updateIndexPattern();
updateIndexPattern(); // assume on this point indexPatternsInPanels are resolved and available
updateIndexPattern();
updateIndexPattern();

⬆️ but because code inside fetches defaults async, it could have happened that earlier calls finish last

Solution

I refactored that piece to use RxJS to get handy cancelations.

I didn't add any test, as not sure about the good way to test this. This fixes a race condition which would be hard to reliably catch in a function test. And dashboard controller need a refactor to start adding unit tests for logic there.

Release notes

Sometimes when creating filters on a dashboard suggestions from default index patterns were shown by mistake.

@Dosant Dosant requested a review from a team July 22, 2020 16:23
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@Dosant Dosant added bug Fixes for quality problems that affect the customer experience v7.9.0 labels Jul 22, 2020
@Dosant Dosant added the Feature:Dashboard Dashboard related features label Jul 22, 2020
@Dosant Dosant added release_note:skip Skip the PR/issue when compiling release notes release_note:fix and removed release_note:skip Skip the PR/issue when compiling release notes labels Jul 22, 2020
@Dosant Dosant marked this pull request as draft July 22, 2020 16:26
@Dosant Dosant marked this pull request as ready for review July 23, 2020 08:43
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good already and it seems like I'm always ending up in the right state, but during loading it shows the warnings the wrong way:
warningstate

Maybe we should pass a "loading" flag of some kind in to prevent "Warning" flags as longs as index patterns are still fetched?

@Dosant
Copy link
Contributor Author

Dosant commented Jul 23, 2020

@flash1293, what if do not show filter bar until index patterns are properly loaded?
(introducing new loading state for filter bar in a sake of this hot fix seems like a risky overkill)

@flash1293
Copy link
Contributor

@Dosant Just realized you want to get this into 7.9, not showing the filter bar is fine for me then. Maybe we can add a nice loading state (Maybe a Loading filters...) in a later version

@Dosant
Copy link
Contributor Author

Dosant commented Jul 23, 2020

Hm, not sure I like this "hotfix" because of context shift:

Jul-23-2020 14-15-51

I am thinking to leave this fix for 7.9 focused on fixing index pattern resolution race condition (no hiding filters bar) and to create a ticket for follow up with proper loading state for filters. WDYT?

@flash1293
Copy link
Contributor

@Dosant Can we hold back the filters till the index patterns are loaded? So rendering an empty filter bar, then passing the filters through once the index patterns are ready?

If that doesn't fit well I would be fine with the current state.

@Dosant
Copy link
Contributor Author

Dosant commented Jul 23, 2020

@flash1293, I'd say doesn't fit :(, filters and index patterns get into filter bar in completely different code paths.

  • Index patterns via react component props
  • Filters via FilterManager service which get's syncing with DashboardStateManger (url)

@flash1293
Copy link
Contributor

@Dosant I'm fine with the current state in that case. @majagrubic are you fine with that approach for now as well? We can improve in 7.10

@Dosant
Copy link
Contributor Author

Dosant commented Jul 27, 2020

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@majagrubic is out this week, it seems like a pretty risky change for 7.9 at this point. @Dosant what do you think about moving this to 7.9.1?

@Dosant Dosant requested a review from ThomThomson July 27, 2020 09:29
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as this is looking fine for me (with room for improvement as discussed) - we can already prepare the backports till we have a decision how to handle it

@lizozom
Copy link
Contributor

lizozom commented Jul 27, 2020

I strongly support fixing this bug and handling loading state during 7.10.
Feel free to create an issue and assign it to me.

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some minor comments.

Dosant added 2 commits July 27, 2020 16:10
…ub.com:Dosant/kibana into dev/fix-dashboard-index-pattern-race-condition
@Dosant
Copy link
Contributor Author

Dosant commented Jul 27, 2020

@lizozom, created an issue to address "flickering" #73286

@Dosant
Copy link
Contributor Author

Dosant commented Jul 28, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

page load bundle size

id value diff baseline
dashboard 679.5KB +697.0B 678.9KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@Dosant Dosant merged commit 9b570a9 into elastic:master Jul 28, 2020
Dosant added a commit to Dosant/kibana that referenced this pull request Jul 28, 2020
* fix dashboard index pattern race condition

* improve

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Dosant added a commit to Dosant/kibana that referenced this pull request Jul 28, 2020
* fix dashboard index pattern race condition

* improve

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Dosant added a commit that referenced this pull request Jul 28, 2020
* fix dashboard index pattern race condition

* improve

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Dosant added a commit that referenced this pull request Jul 28, 2020
* fix dashboard index pattern race condition

* improve

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 28, 2020
* master: (44 commits)
  [Search] add server logs (elastic#72454)
  [SIEM][Timelines] Updates timeline template callout text (elastic#73334)
  Fix App status  flaky test (elastic#72853)
  [Functional Tests] Increase the timeout when locating the tableview] (elastic#73243)
  Use "Apply_filter_trigger" in dashboard drilldown (elastic#71468)
  fix dashboard index pattern race condition (elastic#72899)
  [Functional Tests] Increase waitTime for timelion to fetch the results (elastic#73255)
  [Functional Tests] Fix flakiness on TSVB chart on switching index patterns test (elastic#73238)
  updates cypress to v4.11.0 (elastic#73327)
  [Metrics UI] Saved views bugs (elastic#72518)
  [Ingest Manager] Convert select agent config step to use combo box (elastic#73172)
  Exclude `version` from package config attributes that are copied, add safeguard to package config bulk create (elastic#73128)
  [Security Solution][ML] Updates siem group name to security (elastic#73218)
  [Security Solution] Show proper icon for termination status of all processes (elastic#73235)
  [Security Solution][Resolver] Show origin node details in panel on load (elastic#73313)
  [Security solution] Threat hunting test coverage improvements (elastic#73276)
  [Security Solution][Exceptions] - Update exception item comments to include id (elastic#73129)
  [Enterprise Search] Error state UI tweaks to account for current Cloud SSO behavior (elastic#73324)
  [dev/build/docker_generator] convert to typescript (elastic#73339)
  [APM] Fix focus map link on service map (elastic#73338)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Dashboard Dashboard related features release_note:fix v7.9.0 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dashboard][Filters] Warning filters in non default index pattern dashboard
5 participants